using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using TestWebApi.Entry;

namespace TestWebApi.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        public static readonly string url  = "http://api.yujn.cn/api/dcd.php";
        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
        [HttpGet(Name = "GetImgSaveLocal")]
        public Respone GetImgSaveLocal() {
            //Dictionary<string, string> head = new Dictionary<string, string>();
            var data = JsonConvert.DeserializeObject<Img>(HttpRequest.SendHttp.SendGetByHttp(url, null));
            foreach (string imgurl in data.images)
            {
                ThreadPool.QueueUserWorkItem(TestPool.ImgeUrlToPath, imgurl);
            }
            return Respone.Ok("ok");
        }
    }
}
